//
//  StatusListViewModel.swift
//  LRWeibo
//
//  Created by admin on 15/9/25.
//  Copyright © 2015年 懒人. All rights reserved.


/// 微博数据列表视图模型

import Foundation

class StatusListViewModel{
    
    lazy var statuses = [LRStatusListModel]()

    /// 获取微博信息
    /// - see: [http://open.weibo.com/wiki/2/statuses/home_timeline](http://open.weibo.com/wiki/2/statuses/home_timeline)
    func loadData(finished:(error: NSError?)->())
    {
        let token = UserAccountViewModel.sharedUserAccount.access_token as! AnyObject
        let prams: [String: AnyObject] = ["access_token": token]
        
        NetworkTool.shareNetTool.request(NetworkTool.requestMethod.GET, URLString: "https://api.weibo.com/2/statuses/home_timeline.json", prams: prams, finshBlock: { (result, error) -> () in

            if error != nil
            {
                finished(error: error)
                return
            }
            
            let array = result!["statuses"] as! [[String: AnyObject]] // 包含字典的数组
            var arrayM = [LRStatusListModel]() // 里面是模型数据的数组
            for dict in array
            {
                arrayM.append(LRStatusListModel(dict: dict))
            }

            self.statuses += arrayM
            finished(error: nil)
        })
    }
    

}